/*
 * @Author: muuzi@163.com muuzi@163.com
 * @Date: 2024-09-23 00:53:28
 * @LastEditors: muuzi@163.com muuzi@163.com
 * @LastEditTime: 2024-11-14 23:46:28
 * @FilePath: /my-vue3-project/vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import { visualizer } from "rollup-plugin-visualizer";
// import commonjs from '@rollup/plugin-commonjs';
import createPlugins from "./vite/plugins";
export default defineConfig(({ command, mode, ssrBuild }) => {
  const env = loadEnv(mode, process.cwd());

  return {
    plugins: [
      // commonjs(),
      uni(),
      visualizer(),
      createPlugins(env, command === "serve"),
    ],
    server: {
      host: "0.0.0.0",
      port: Number(env.VITE_APP_PORT),
      open: true,
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: env.VITE_APP_BASE_URL,
          changeOrigin: true,
          ws: true,
          rewrite: (path) =>
            path.replace(new RegExp("^" + env.VITE_APP_BASE_API), ""),
        },
      },
    },
    // dev 独有配置
  };
});
